<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>用户登录页</title>
    <link rel="stylesheet" href="/css/bootstrap.min.css">
    <script src="/js/jquery-3.6.0.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>


    <style>
        b{
            font-weight: bolder;
            color: red;
        }

    </style>
    <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.min.css">
</head>
<body>

<style>
    .abc
    {
        text-decoration:none;
        color:skyblue;
        font-style: oblique;
        font-size: large;
        margin-left: 40%;
        margin-right: 40%;
        margin-bottom: 20px;

    }


    li{ list-style-type:none}
    #bgBox {
        display: none;
        opacity: 0;
        z-index: -2;
        position: absolute;
        width: 100%;
        height: 100%;
        object-fit: cover;
        transition: opacity 1s,transform .25s,filter .25s;
    }

    body {
        max-width: 100%;
        overflow: hidden;
        margin-bottom: 50px;
        background-repeat: no-repeat;
        background-size: cover;
        background-position: center;
        cursor: default;
        -webkit-tap-highlight-color: transparent;
        -webkit-user-select: none;
        user-select: none;
    }

    .logining {
        position: absolute;
        top: 200px;
        left: 50%;
        transform: translateX(-50%);
        width: 440px;
        height: 1000px;
        max-height: 80%;
        max-width: 80%;
        padding: 10px 15px;
        margin-bottom: 1000px;
        border-radius: 30px;
        text-align: center;
        font-size: 81%;
        color: black;
    }

</style>


<div id="body">
    <p class="abc" >🎉🎉欢迎您来到成绩管理系统🎉🎉</p>
    <img id="bgBox" class="" src="https://s2.loli.net/2022/01/05/NylnjJ7dDcEkhws.jpg" style="display: block; opacity: 1;">
    <div class="cover" id="cover" style="opacity: 1;"></div>
</div>

<div class="logining"id="logining">

<div class="container-fluid">
    <div class="panel panel-default">
        <div class="panel-heading"Panel heading without title></div>
        <div class="panel-body">
            <form >
                <div class="form-group">
                    <label for="username" style="margin-left: -300px">用户名🎈：</label>
                    <input type="text" class="form-control"id="username"name="username" placeholder="用户名">
                </div>
                <div class="form-group">
                    <label for="password" style="margin-left: -300px">密码🔒：</label>
                    <input type="password" class="form-control"id="password" name="password" placeholder="密码">
                </div>
                <form >
                    <select id="userID">
                        <option selected="selected" name="1" value="1">学生</option>
                        <option  name="2"value="2">管理员</option>
                    </select>
                    <button type="button"class="btn btn-default" onclick="login();">登录</button>
                </form>

            </form>
        </div>
    </div>
</div>
</div>

<script type="text/javascript">

    function login(){
        //通过id来获取对应的value值
        var sname=$("#username").val();
        var psw=$("#password").val();
        var UserID=$("#userID option:selected").val();//救命我居然把id写成UserID，应该是userID
        if(!window.localStorage){
            alert("浏览器不支持localstorage");
        }else{
            var storage=window.localStorage;
            //写入a字段
            storage["name"]=sname;
        }
        $.ajax({
            url:"/webapi/login/user",
            //传递的数据
            data:{
                username:sname,
                password:psw,
                UserID:UserID
            }
            //调用之后将会返回controller里面的返回值-1和1，我们这里的返回值用rs表示
        }).done(function (rs){
            if(rs==1){
                //成功：
                    window.location.href="/toPage?url=/student/student";
            }
            else if(rs==2){
                window.location.href="/toPage?url=/admin/manage";
            }
            else {
                alert("出错了，您的用户名和密码是乱写的吗？");
            }
        });
    }
</script>

</body>
</html>